package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.rest.vo.ChapterVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.Chapter;
import com.ruoyi.book.service.IChapterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节列表Controller
 * 
 * @author ruoyi
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/book/chapter")
public class ChapterController extends BaseController
{
    @Autowired
    private IChapterService ChapterService;

    /**
     * 查询章节列表列表
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(Chapter Chapter)
    {
        startPage();
        List<ChapterVo> list = ChapterService.selectChapterList(Chapter);
        return getDataTable(list);
    }

    /**
     * 导出章节列表列表
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:export')")
    @Log(title = "章节列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Chapter Chapter)
    {
        List<ChapterVo> list = ChapterService.selectChapterList(Chapter);
        ExcelUtil<ChapterVo> util = new ExcelUtil<ChapterVo>(ChapterVo.class);
        util.exportExcel(response, list, "章节列表数据");
    }

    /**
     * 获取章节列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ChapterService.selectChapterById(id));
    }

    /**
     * 新增章节列表
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:add')")
    @Log(title = "章节列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Chapter Chapter)
    {
        return toAjax(ChapterService.insertChapter(Chapter));
    }

    /**
     * 修改章节列表
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:edit')")
    @Log(title = "章节列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Chapter Chapter)
    {
        return toAjax(ChapterService.updateChapter(Chapter));
    }

    /**
     * 删除章节列表
     */
    @PreAuthorize("@ss.hasPermi('book:chapter:remove')")
    @Log(title = "章节列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ChapterService.deleteChapterByIds(ids));
    }
}
